﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using ProjectPigs.Assets;
using ProjectPigs.Core;

namespace ProjectPigs.Scenes
{
    class SceneManager
    {
        static List<GameScene> scenes = new List<GameScene>();
        static GameScene activeScene;

        public static void Initialize(Map[] maps)
        {
            foreach (Map map in maps)
            {
                scenes.Add(new GameScene(map.Name, map));
            }

            SceneManager.activeScene = scenes[0];
        }

        public static void update(GameTime time)
        {

                if (activeScene is GameScene)
                {
                    (activeScene as GameScene).update(time);
                    (activeScene as GameScene).lateUpdate(time);
                    (activeScene as GameScene).guiUpdate(time);
                }
            
        }

        public static void draw(SpriteBatch sb)
        {
   
                if (activeScene != null)
                {
                    (activeScene as GameScene).draw(sb);
                    Debug.setEntry("Active Scene: "+activeScene.Name+" ("+activeScene.MeshCount+" meshes, "+activeScene.GameObjectCount+" gObjects)", 0, 4);
                }
            
        }

        public static void activateScene(Scene scene)
        {

        }

        public static void activateScene(int index)
        {
            if (index < 0 || index > scenes.Count() - 1) return;

            destroyCurrentScene();
            activeScene = scenes[index];
        }

        public static void activateScene(String name)
        {
            foreach (Scene scene in scenes)
            {
                if (scene.Name == name)
                {
                    activeScene = (scene as GameScene);
                }
            }
        }
        private static void destroyCurrentScene()
        {

        }

  
    }
}
